package LeetCode.month01.day11;

public class No240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;
        for (int i = 0; i < m; i++) {
            if(target>matrix[i][n-1]) continue;
            if(target<matrix[i][0]) return false;
            for (int j = 0; j < n; j++) {
                if(matrix[i][j]==target) return true;
                if(matrix[i][j]>target) break;
            }
        }
        return false;
    }

    public boolean search(int[][]matrix,int target){
        int x = 0;
        int y = matrix[0].length-1;
        while(x<matrix.length&&y>=0){
            if(matrix[x][y]==target) return true;
            else if(target>matrix[x][y]) x++;
            else y--;
        }
        return false;
    }
}
